package springMvc;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

 
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class UploadFileController {
	@RequestMapping("uploadFile")
	public String UploadFile(@RequestParam("upload")MultipartFile file,HttpServletRequest request,Model model) {
		System.out.println("进入文件上传");
		System.out.println(file.getOriginalFilename());
	    String path=request.getServletContext().getRealPath("/phone");
		File targeFile=new File(path, file.getOriginalFilename());
		model.addAttribute("fName", file.getOriginalFilename());
		try {
			file.transferTo(targeFile);
		} catch (IllegalStateException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "UploadSuccess";
	}
}
